import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'ContainAND.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState

    return new Page();
  }
}

class Page extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return layout(context);
  }

  Widget layout(BuildContext context) {
    return new Scaffold(
      body:
      Column(
        children: <Widget>[
          Expanded(
            flex:2,
            child: Container(
              height:200,
              child: Swiper(
                  itemBuilder: (BuildContext context, int Index) {
                    return Image.network(
                        "http://img.zcool.cn/community/01ed9c55499c160000019ae993c9a4.jpg@2o.jpg",
                        fit: BoxFit.fill);
                  },
                  itemCount: 5,
                  scrollDirection: Axis.horizontal,
                  loop: true,
                  duration: 300,
                  autoplay: true,
                  onIndexChanged: (index) {},
                  onTap: (index) {},
                  pagination: SwiperPagination(
                      alignment: Alignment.bottomRight,
                      margin: EdgeInsets.only(bottom: 20.0, right: 20.0),
                      builder: DotSwiperPaginationBuilder(
                          color: Colors.black54, activeColor: Colors.white)),
                  autoplayDisableOnInteraction: true),
            ),
          ),
          Expanded(
            flex: 10,
            child: Container(
              margin: EdgeInsets.all(0),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(8),
                boxShadow: [
                  BoxShadow(
                    blurRadius: 6,
                    spreadRadius: 4,
                    color: Color.fromARGB(20, 0, 0, 0),
                  ),
                ],
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  renderCover(context),
                  renderUserInfo(context),

                ],
              ),
            ),
          ),
          //header(context),
        ],
      ),
    );
  }

  Widget renderUserInfo(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 16),
      padding: EdgeInsets.symmetric(horizontal: 16),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            children: <Widget>[
              CircleAvatar(
                radius: 20,
                backgroundColor: Color(0xFFCCCCCC),
                backgroundImage: NetworkImage("http://i2.yeyou.itc.cn/2014/huoying/hd_20140925/hyimage06.jpg"),
              ),
              Padding(padding: EdgeInsets.only(left: 8)),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    "eqeqeqe",
                    style: TextStyle(
                      fontSize: 15,
                      fontWeight: FontWeight.bold,
                      color: Color(0xFF333333),
                    ),
                  ),
                  Padding(padding: EdgeInsets.only(top: 2)),
                  Text(
                    "http://i2.eqeeqeqeqeqeq2222.jpg",
                    maxLines: 2,
                    style: TextStyle(
                      fontSize: 12,
                      color: Color(0xFF999999),
                    ),
                  ),
                ],
              ),
            ],
          ),
          Text(
            "http://6.jpg",
            style: TextStyle(
              fontSize: 13,
              color: Color(0xFF999999),
            ),
          ),
        ],
      ),
    );
  }
  Widget renderCover(BuildContext context) {
    return Stack(
      fit: StackFit.passthrough,
      children: <Widget>[
        ClipRRect(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(8),
            topRight: Radius.circular(8),
          ),
          child: Image.network(
            "http://i2.yeyou.itc.cn/2014/huoying/hd_20140925/hyimage06.jpg",
            fit: BoxFit.fitWidth,
          ),
        ),

      ],
    );
  }

  Widget buildAppBar(BuildContext context) {
    return new AppBar(title: const Text('首页'));
  } //不要导航栏 这样去把一个整体比较复杂的方法进行页面间的布局调整
//Widget buildAppBar(BuildContext context){
  // return new AppBar(title:const Text('eqeqeq'));
//}

  Widget header(BuildContext context) {
    return new Image.network(
      'http://i2.yeyou.itc.cn/2014/huoying/hd_20140925/hyimage06.jpg',
    );
  }
}
